// Program to search a key using Binary search

class BinarySearch{
	static void search(int[] a,int key){
		int low,high,mid=0;
		high = a.length-1;
		low = 0;
		while(low <= high){
			mid = (low+high)/2;
			if (key > a[mid])
				low = mid + 1;
			else if (key < a[mid])
				high = mid - 1;
			else
				break;
		}
		if (key == a[mid])
			System.out.println("Key = " + key + " found at pos " + mid);
		else
			System.out.println("Key not found");
		
	}
	public static void main(String[] srch){
		int[] arr = {1,2,3,5,7,8};
		int key = 8;
		search(arr,key);	
	}
}